//
//  XJMeHeaderView.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/3.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJMeHeaderView.h"

@implementation XJMeHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (UIView *)backgroundView{
    if (!_backgroundView) {
        UIView * backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWidth, ADAPTWidth(130))];
        self.backgroundView = backgroundView;
    }
   // [self addSubview:_backgroundView];
    return _backgroundView; 
}

//用户昵称
- (UILabel *)xjme_nameLab{
    
    if (!_xjme_nameLab) {
        UILabel * xjme_nameLab = [UILabel new];
        self.xjme_nameLab=xjme_nameLab;
        [self addSubview:xjme_nameLab];
    }
    return _xjme_nameLab;
}

//性别、手机
- (UILabel *)xjme_sexPhoneLab{
    
    if (!_xjme_sexPhoneLab) {
        UILabel * xjme_sexPhoneLab = [UILabel new];
        self.xjme_sexPhoneLab=xjme_sexPhoneLab;
        [self addSubview:xjme_sexPhoneLab];
    }
    return _xjme_sexPhoneLab;
}

//用户编号
- (UILabel *)xjme_userNumLab{
    
    if (!_xjme_userNumLab) {
        UILabel * xjme_userNumLab = [UILabel new];
        self.xjme_userNumLab=xjme_userNumLab;
        [self addSubview:xjme_userNumLab];
    }
    return _xjme_userNumLab;
}

//头像
- (UIImageView *)xjme_iconImgV{
    
    if (!_xjme_iconImgV) {
        UIImageView * xjme_icnImgV = [UIImageView new];
        self.xjme_iconImgV=xjme_icnImgV;
        [self addSubview:xjme_icnImgV];
        
        _xjme_iconImgV.userInteractionEnabled = YES;
        //添加手势
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesAction)];
        [_xjme_iconImgV addGestureRecognizer:tapGes];
    }
    return _xjme_iconImgV;
}


//添加子控件
- (void)setupSubviews{
    //用户昵称
    self.xjme_nameLab.text      =   @"张小花";
    self.xjme_nameLab.font      =   XJFONTSET_M(20);
    self.xjme_nameLab.textColor =   XJCOLOR_RGB(17, 17, 17);
    
    CGFloat xjme_nameLabW = [UILabel labelWithLabel:self.xjme_nameLab getWidthWithTitle:self.xjme_nameLab.text font:self.xjme_nameLab.font];
    CGFloat xjme_nameLabH = [UILabel labelWithLabel:self.xjme_nameLab getHeightByWidth:xjme_nameLabW title:self.xjme_nameLab.text font:self.xjme_nameLab.font];
    
    self.xjme_nameLab.sd_layout
    .leftSpaceToView(self, ADAPTWidth(25))
    .topSpaceToView(self, ADAPTHeight(23))
    .widthIs(xjme_nameLabW)
    .heightIs(xjme_nameLabH);
    
    //性别手机
    self.xjme_sexPhoneLab.text      =   [NSString stringWithFormat:@"%@ %@",@"女",@"15888888888"];
    self.xjme_sexPhoneLab.font      =   XJFONTSET_R(13);
    self.xjme_sexPhoneLab.textColor =   XJCOLOR_RGB(121, 130, 133);
    
    CGFloat xjme_sexPhoneLabW = [UILabel labelWithLabel:self.xjme_sexPhoneLab getWidthWithTitle:self.xjme_sexPhoneLab.text font:self.xjme_sexPhoneLab.font];
    CGFloat xjme_sexPhoneLabH = [UILabel labelWithLabel:self.xjme_sexPhoneLab getHeightByWidth:xjme_sexPhoneLabW title:self.xjme_sexPhoneLab.text font:self.xjme_sexPhoneLab.font];
    
    self.xjme_sexPhoneLab.sd_layout
    .leftEqualToView(self.xjme_nameLab)
    .topSpaceToView(self.xjme_nameLab, ADAPTHeight(5))
    .widthIs(xjme_sexPhoneLabW)
    .heightIs(xjme_sexPhoneLabH);
    
    //用户编号
    self.xjme_userNumLab.text       =   [NSString stringWithFormat:@"%@ %@",@"用户编号",@"788877665566"];
    self.xjme_userNumLab.font       =   XJFONTSET_R(13);
    self.xjme_userNumLab.textColor  =   XJCOLOR_RGB(121, 130, 133);
    
    CGFloat xjme_userNumLabW = [UILabel labelWithLabel:self.xjme_userNumLab getWidthWithTitle:self.xjme_userNumLab.text font:self.xjme_userNumLab.font];
    CGFloat xjme_userNumLabH = [UILabel labelWithLabel:self.xjme_userNumLab getHeightByWidth:xjme_userNumLabW title:self.xjme_userNumLab.text font:self.xjme_userNumLab.font];
    
    self.xjme_userNumLab.sd_layout
    .leftEqualToView(self.xjme_nameLab)
    .topSpaceToView(self.xjme_sexPhoneLab, ADAPTHeight(5))
    .widthIs(xjme_userNumLabW)
    .heightIs(xjme_userNumLabH);
    
    //头像
    self.xjme_iconImgV.image = [UIImage imageNamed:@"default_head"];
    self.xjme_iconImgV.layer.masksToBounds=YES;
    self.xjme_iconImgV.contentMode=UIViewContentModeScaleAspectFill;
    self.xjme_iconImgV.layer.cornerRadius=ADAPTWidth(70)/2;
    
    self.xjme_iconImgV.sd_layout
    .rightSpaceToView(self, 27)
    .topEqualToView(self.xjme_nameLab)
    .widthIs(ADAPTWidth(70))
    .heightIs(ADAPTWidth(70));
    self.xjme_iconImgV.sd_cornerRadiusFromWidthRatio=@(0.5);//适配圆形
}


- (void)configureXJMeHeaderViewWithName:(NSString *)name sex:(NSString *)sex phone:(NSString *)phone userNumber:(NSString *)userNumber iconStr:(NSString *)iconStr{
    self.xjme_nameLab.text      =   name;

    self.xjme_sexPhoneLab.text      =   [NSString stringWithFormat:@"%@ %@",sex,phone];
    self.xjme_userNumLab.text       =   [NSString stringWithFormat:@"%@ %@",@"用户编号",userNumber];

    
    UIImage *defaultHead = [UIImage imageNamed:@"default_head"];
    [self.xjme_iconImgV sd_setImageWithURL:[NSURL URLWithString:iconStr] placeholderImage:defaultHead];
}


#pragma mark - 点击事件
- (void)tapGesAction {
    if (self.clickHeadeIconBlock) {
        self.clickHeadeIconBlock();
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
